<template>
  <div class="New_build">
    <div class="mask"></div>
    <div class="new_build">
      <div class="build-top">
        <p>新建资料（仓库盘点）</p>
        <i class="el-icon-close" @click="closeNew_build"></i>
      </div>

      <div class="build-info">
        <div class="build-info-1">
          <p>盘点日期</p>
          <el-date-picker v-model="checkDate" type="date"> </el-date-picker>
          <p>仓库编号</p>
          <!-- <el-input :disabled="Dis" v-model="warehouseNo" class="build-inp"></el-input> -->
          <el-select :disabled="Dis" v-model="warehouseNo" class="build-inp">
            <el-option
              v-for="item in warehouseList"
              :key="item.value"
              :label="item.value"
              :value="item.value"
            >
              <span style="float: left">{{ item.value }}</span>
              <span style="float: right">{{ item.label }}</span>
            </el-option>
          </el-select>

          <p>盘点序号</p>
          <el-input v-model="sequence" disabled></el-input>
          <p>单据号</p>
          <el-input v-model="receiptsNumber"></el-input>
        </div>

        <div class="build-info-4">
          <el-table
            border
            :data="codeData"
            id="codeTable"
            style="width: 100%; margin-bottom: 20px"
            max-height="148px"
            :header-cell-style="{
              background: '#f4f4f4',
              padding: 0,
              height: '40px'
            }"
            @cell-click="cellClick"
            :cell-style="{ padding: 0, height: '36px' }"
          >
            <el-table-column :label="header"> </el-table-column>
            <el-table-column prop="colorName" label="颜色"> </el-table-column>
            <!-- <el-table-column
            prop="colorNo"
            label="颜色編號">
          </el-table-column> -->

            <template v-for="col in sizeList">
              <el-table-column
                :key="col + Math.random()"
                :prop="col"
                :label="col"
              >
                <template slot-scope="scope">
                  <!-- <el-form :v-model="scope.row"> -->
                  <!-- <el-form-item> -->
                  <!-- <el-input v-model="scope.row[col]" @blur="handleClick(scope.$index,scope.row[col])" ></el-input>
                  <span>{{scope.row[col]}}</span> -->
                  <!-- </el-form-item> -->
                  <!-- </el-form> -->

                  <el-input
                    size="small"
                    class="innerInp"
                    v-model="scope.row[col]"
                    @blur="
                      handleClick($event, {
                        index: scope.$index,
                        key: col,
                        result: scope.row[col]
                      })
                    "
                    @keyup.enter.native="inpEnter"
                  >
                  </el-input>
                </template>
              </el-table-column>
            </template>
          </el-table>
        </div>

        <div class="barcode">
          <p>条码扫描</p>
          <el-switch
            v-model="isBarcode"
            :disabled="isDis"
            active-color="#409EFF"
            inactive-color="#C0C4CC"
          >
          </el-switch>
          <el-radio :disabled="!isBarcode" v-model="radio" label="1"
            >货号码</el-radio
          >
          <el-radio :disabled="!isBarcode" v-model="radio" label="2"
            >ID码</el-radio
          >
          <i
            class="el-icon-question"
            style="color: #017aff; margin: 4px 6px 0 15px"
          ></i>
          <p>冲减单子. 点"款号"， 请按F7，把数量填成-1</p>
        </div>

        <div class="enterBarcode">
          <el-input
            id="input"
            @keyup.enter.native="scanning($event)"
            v-model="searchValue"
            placeholder="扫描/输入条码,按回车键"
          ></el-input>
          <p style="margin: 15px 0 0 5px">合计：{{ howMany }}</p>
        </div>

        <el-table
          height="430px"
          :data="barcodeData"
          style="width: 100%"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '36px' }"
          highlight-current-row
          @row-click="rowClick"
        >
          <el-table-column
            show-overflow-tooltip
            prop="kindsNumber"
            label="款号"
            width="140px"
          >
          </el-table-column>
          <el-table-column prop="colorName" label="颜色"> </el-table-column>
          <el-table-column prop="sizeNo" label="尺码编号" width="145px">
          </el-table-column>
          <el-table-column prop="sum" label="数量" width="70px">
          </el-table-column>
          <el-table-column prop="sellingPrice" label="单价"> </el-table-column>
          <el-table-column prop="onePrice" label="金额"> </el-table-column>
          <el-table-column prop="sellingPrice" label="售价"> </el-table-column>
          <el-table-column prop="commodityName" label="品名"> </el-table-column>
          <el-table-column prop="brandedName" label="品牌"> </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="enteringTime"
            label="录入日期"
            width="90px"
          >
          </el-table-column>
        </el-table>
      </div>

      <div class="build-btn">
        <div style="margin: 5px 20px 0 0">
          <el-button @click="closeNew_build">取消</el-button>
          <el-button type="primary" plain @click="saveNew_build"
            >保存</el-button
          >
          <el-button type="primary" @click="keepGoing">继续录入</el-button>
        </div>
      </div>
    </div>

    <div class="popup" :style="{ display: showPopup }">
      <div class="popup_t">
        <p>输入扫描数量</p>
        <i
          class="el-icon-close"
          @click="
            () => {
              this.showPopup = 'none'
            }
          "
        ></i>
      </div>
      <div class="popup_c">
        <p>请输入扫描数量</p>
        <p>如果不输入则扫描数量为1</p>
        <el-input v-model="scanNum" style="margin-top: 10px"></el-input>
        <!-- <input type="text" v-model="scanNum" class="popup_button"> -->
      </div>
      <div class="popup_b">
        <el-button
          @click="
            () => {
              this.showPopup = 'none'
            }
          "
          >取消</el-button
        >
        <el-button @click="preservation" type="primary">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {
  kindsNumberOutContinue,
  kindsNumberOut
} from '../../../../network/customerOutTotal'
import { postNewbuild, getWarehouse } from '../../../../network/warehouse'
import {
  getScanning,
  searchKindsNumber,
  getBarCode,
  factoryInputScanner
} from '../../../../network/manufacturer'
import { getKindsNumberList } from '../../../../network/artNo'
import today from '../../../../components/mixins/today'
import enterUp from '../../../../components/mixins/enterUp'
// import { delete } from 'vue/types/umd'
function compare(property) {
  return function (a, b) {
    var value1 = a[property]
    var value2 = b[property]
    return value1 - value2
  }
}
export default {
  mixins: [today, enterUp],
  props: {
    warehouse: {
      type: String,
      default: ''
    },
    sequenceData: {
      type: String,
      default: ''
    }
  },
  created() {
    this.inpList = this.getInput() //input enter移动
    this.checkDate = this.getNowTime()
    //仓库编号
    getWarehouse().then((res) => {
      // console.log(res.data.data)
      res.data.data.forEach((e) => {
        this.warehouseList.push({
          label: e.name,
          value: e.no,
          Main: e.isMainWarehouse
        })
      })
      for (let a of res.data.data) {
        if (a.isMainWarehouse == 1) {
          this.warehouseNo = a.no //主仓库
        }
      }
    })
  },

  data() {
    return {
      manufacturerBarCode: {},
      kl: '',
      isDis: false,
      inpList: [],
      checkDate: [],
      receiptsNumber: '',
      warehouseList: [],
      Dis: false,
      deta: [],
      id: '',
      isKindsNumber: '',
      obj2: [],
      header: '',
      AAa: [],
      Rid: [],
      showPopup: 'none',
      differTime: new Date(),
      warehouseNo: '',
      scanNum: 1,
      differMoney: '',
      sequence: '',
      sellingPrice: '',
      cols: ['7', '9', '1', '3', '5', '7', 'F'],
      isBarcode: false,
      radio: '1',
      searchValue: '',
      codeData: [],
      barcodeData: [],
      size: [],
      colorNo: '',
      kindsNumbers: '',
      tmpBarcodeData: [],
      sizeList: [],
      XHList: [],
      XHList1: [],
      barcodeData1: [],
      howMany: ''
    }
  },
  methods: {
    sibling(e) {
      let s = []
      let pp = e.parentNode.parentNode.children
      console.log(pp)
      for (let j = 0; j < pp.length; j++) {
        let p = pp[j].children
        for (let i = 0, pl = p.length; i < pl; i++) {
          if (p[i] !== e) s.push(p[i])
        }
      }
      return s
    },
    cellClick(row, column, cell, event) {
      // console.log(row)  //当行的全部数据
      // console.log(column)  //当列的全部数据
      // console.log(cell)  //点击格的html代码  td>div
      // console.log(event)  //MouseEvent
      // console.log(cell.innerHTML)

      // console.log(cell.children[0].children[0].children)
      // cell.children[0].children[0].children[0].focus()
      cell.classList.add('activeCell')
      let s = this.sibling(cell)
      s.forEach((e) => {
        e.classList.remove('activeCell')
      })
    },
    handleClick(e, { index, key, result }) {
      e.target.parentNode.parentNode.parentNode.classList.remove('activeCell')
      // let r = /^\+?[1-9][0-9]*$/
      let r = /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/
      if (result != 0) {
        result = result.replace(/\b(0+)/gi, '')
      }
      if (!r.test(result) && result) {
        this.$alert('数量请输入整数', '', {
          confirmButtonText: '确定'
        })
        this.codeData[index][key] = 0
        return
      }
      this.codeData[index][key] = result
      // for(let s of this.codeData){
      //   this.colorNo = s.colorNo
      // }
      // console.log(this.codeData)

      // this.kindsNumbers = `${this.searchValue}-${this.colorNo}${key}`
      // console.log(this.kindsNumbers)
      // getScanning({isKindsNumber:true,searchValue:this.kindsNumbers}).then(res=>{
      //   console.log(res.data)
      //   if(res.data.code == 200){
      //   this.barcodeData.push(res.data.data[0])
      //   }
      // })
      // console.log(this.barcodeData)
    },

    inpEnter(e) {
      // console.log(e)
      e.target.parentNode.parentNode.parentNode.classList.remove('activeCell')
    },

    closeNew_build() {
      this.scanNum = 1
      this.howMany = ''
      // this.warehouseNo = '';
      this.searchValue = ''
      this.codeData = []
      this.barcodeData = []
      this.barcodeData1 = []
      this.isBarcode = false
      this.Dis = false
      this.sequence = ''
      this.receiptsNumber = ''
      this.$emit('closeNew_build')
    },

    //保存数据
    saveNew_build() {
      if (this.checkDate == '' || this.warehouseNo == '') {
        this.$message({
          type: 'error',
          message: '调拨日期，仓库编号不能为空'
        })
        return
      }

      let ie = []
      let io = []
      let ip = []
      let iu = {}
      let il
      for (let y in this.barcodeData) {
        //输入款号去掉未输入数字的然后保存
        if (this.barcodeData[y].sum == '') {
          this.barcodeData.splice(y, 1)
        }
      }
      for (let t of this.barcodeData) {
        if (this.radio == '1') {
          ie.push(t.kindsNumber)
          il = 1
        } else if (this.isBarcode && this.radio == '2') {
          // ie.push(t.rfID)
          // console.log(ip)
          il = 2
        }

        io.push(t.sum)
        for (let g in ie) {
          for (let h in io) {
            if (g == h) {
              iu[ie[g]] = io[h] //属性值作为属性名
            }
          }
        }
      }

      let or = ''
      if (this.isBarcode == false) {
        or = 1
      }
      if (this.isBarcode && this.radio == '1') {
        or = 1
      } else if (this.isBarcode && this.radio == '2') {
        or = 0
      }
      let params = {
        checkDate: this.checkDate,
        dataSource: Number(or),
        enteringTime: this.getNowTime(),
        kindsNumberMap: iu,
        receiptsNumber: this.receiptsNumber,
        sequence: this.sequence,
        showCodeList: this.Rid,
        warehouseNo: this.warehouseNo
      }
      console.log(params)
      this.$emit('saveNew_build', params)
      // console.log(this.barcodeData)
      this.Rid = []

      // console.log(JSON.stringify(this.barcodeData).replace(/^\[|\]$/g,''))//去掉最外层中括号
      // AddWarehouse(JSON.stringify(this.barcodeData).replace(/^\[|\]$/g,'')).then(res=>{
      this.howMany = ''
      this.barcodeData = []
      this.barcodeData1 = []
      // this.warehouseNo = ''
      this.searchValue = ''
      this.isDis = false
      this.sequence = ''
      this.receiptsNumber = ''
    },

    keepGoing() {
      if (this.checkDate == '' || this.warehouseNo == '') {
        this.$message({
          type: 'error',
          message: '调拨日期，仓库编号不能为空'
        })
        return
      }
      // let ie = []
      // let io = []
      // let ip = []
      // let iu = {}
      // let il
      // for(let t of this.barcodeData){
      //   if(this.radio == '1'){
      //     ie.push(t.kindsNumber)
      //     il = 1
      //   }
      //   else if(this.isBarcode && this.radio == '2'){
      //     // ie.push(t.rfID)
      //     // console.log(ip)
      //     il = 2
      //   };

      //   io.push(t.sum)
      //   for(let g in ie){
      //       for(let h in io){
      //         if(g == h){
      //           iu[ie[g]] = io[h] //属性值作为属性名
      //         }
      //       }
      //     }
      // }

      // let or = ''
      // if(this.isBarcode && this.radio == '1'){
      //   or = 1
      // }else if(this.isBarcode && this.radio =='2'){
      //   or = 0
      // }
      // let params = {
      //   checkDate:this.checkDate,
      //   dataSource:Number(or),
      //   enteringTime:this.getNowTime(),
      //   kindsNumberMap:iu,
      //   receiptsNumber:this.receiptsNumber,
      //   sequence:this.sequence,
      //   showCodeList:this.Rid,
      //   warehouseNo:this.warehouseNo
      // }
      // console.log(params)
      // this.$emit("keepGoing",params)
      // this.Rid = []
      // this.barcodeData = []
      // this.searchValue = ''
      // this.receiptsNumber = ''
      // this.InpFocus()
      if (!this.isBarcode) {
        this.continueInput()
        this.codeData = []
      } else {
        this.scanning()
      }
    },

    // 继续录入
    continueInput() {
      if (!this.warehouseNo) {
        this.$alert('仓库不能为空', '', {
          confirmButtonText: '确定'
        })
        return
      }

      let isNew = false
      let kindsNumberNumMap = {}
      if (this.isBarcode) {
        // 扫描
        if (this.radio == 1) {
          // 扫描货号码
          kindsNumberNumMap[this.searchValue] = this.scanNum
        } else if (this.radio == 2) {
          // 扫描ID码
          searchKindsNumber({
            // 条码与货号是否一致
            isSame: false,
            // 是否开启条码扫描
            isScanner: true,
            searchValue: this.searchValue
          }).then((res) => {
            console.log(res)
            kindsNumberNumMap[res.data.data[0].kindsNumber] = this.scanNum
          })
        }
      } else {
        // 输入
        console.log(this.codeData)
        console.log(this.sizeList)
        let knList = []
        this.codeData.forEach((e) => {
          let c = e.colorNo
          this.sizeList.forEach((f) => {
            console.log(e[f])

            if (this.manufacturerBarCode.styleColorSize) {
              // 型色尺

              if (this.manufacturerBarCode.styleColor) {
                // 款号与尺码之间有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}-${f}-${c}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}-${f}${c}`,
                    sum: e[f]
                  })
                }
              } else {
                // 款号与尺码之间没有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}${f}-${c}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}${f}${c}`,
                    sum: e[f]
                  })
                }
              }
            } else {
              // 型色尺

              if (this.manufacturerBarCode.styleColor) {
                // 款号与颜色之间有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}-${c}-${f}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}-${c}${f}`,
                    sum: e[f]
                  })
                }
              } else {
                // 款号与颜色之间没有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}${c}-${f}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}${c}${f}`,
                    sum: e[f]
                  })
                }
              }
            }
          })
        })
        console.log(knList)
        this.XHList1 = knList
      }
      for (let f in this.XHList1) {
        if (this.XHList1[f].sum == '') {
          //按款号输入 如果数量未填删除这条数据
          this.XHList1.splice(f, 1)
        }
      }

      for (let a in this.XHList1) {
        for (let b in this.XHList) {
          console.log(this.XHList1)
          if (
            this.XHList1[a].kindsNumber == this.XHList[b].kindsNumber &&
            this.XHList1[a].sum != ''
          ) {
            this.XHList[b]['sum'] = this.XHList1[a].sum
            this.XHList[b]['onePrice'] =
              Number(this.XHList[b].sum) * Number(this.XHList[b].sellingPrice)
            this.XHList[b]['dataSource'] = 1
            this.barcodeData1.push(this.XHList[b])
            console.log(this.barcodeData1)
            this.aka()
          }
        }
      }
    },

    aka() {
      //数组对象里 kindsNumber相同  数量相加 合并
      var tmp = {}
      for (let u in this.barcodeData1) {
        var key = this.barcodeData1[u].kindsNumber
        console.log(tmp[key])
        if (tmp[key]) {
          tmp[key].kindsNumber = this.barcodeData1[u].kindsNumber
          tmp[key].sum += Number(this.barcodeData1[u].sum)

          tmp[key].waveBand = this.barcodeData1[u].waveBand
          tmp[key].vipPrice = this.barcodeData1[u].vipPrice
          tmp[key].supplier = this.barcodeData1[u].supplier
          tmp[key].styleNumber = this.barcodeData1[u].styleNumber
          tmp[key].status = this.barcodeData1[u].status
          tmp[key].statistics = this.barcodeData1[u].statistics
          tmp[key].splitNumber = this.barcodeData1[u].splitNumber
          tmp[key].softwareCustomerId = this.barcodeData1[u].softwareCustomerId
          tmp[key].sizeNo = this.barcodeData1[u].sizeNo
          tmp[key].sizeKind = this.barcodeData1[u].sizeKind
          tmp[key].size = this.barcodeData1[u].size
          tmp[key].sellingPriceTwo = this.barcodeData1[u].sellingPriceTwo
          tmp[key].sellingPriceThree = this.barcodeData1[u].sellingPriceThree
          tmp[key].sellingPriceOne = this.barcodeData1[u].sellingPriceOne
          tmp[key].sellingPriceFour = this.barcodeData1[u].sellingPriceFour
          tmp[key].sellingPrice = this.barcodeData1[u].sellingPrice
          tmp[key].relevanceSize = this.barcodeData1[u].relevanceSize
          tmp[key].quarter = this.barcodeData1[u].quarter
          tmp[key].originalManufacturerKindsNumber =
            this.barcodeData1[u].originalManufacturerKindsNumber
          tmp[key].originalKindsNumber =
            this.barcodeData1[u].originalKindsNumber
          tmp[key].onePrice = this.barcodeData1[u].onePrice
          tmp[key].newSize = this.barcodeData1[u].newSize
          tmp[key].newKindsNumber = this.barcodeData1[u].newKindsNumber
          tmp[key].mnemonicCode = this.barcodeData1[u].mnemonicCode
          tmp[key].matchStyle = this.barcodeData1[u].matchStyle
          tmp[key].manufacturerType = this.barcodeData1[u].manufacturerType
          tmp[key].manufacturerPrice = this.barcodeData1[u].manufacturerPrice
          tmp[key].kindSort = this.barcodeData1[u].kindSort
          tmp[key].image = this.barcodeData1[u].image
          tmp[key].id = this.barcodeData1[u].id
          tmp[key].generalizePrice = this.barcodeData1[u].generalizePrice
          tmp[key].discount = this.barcodeData1[u].discount
          tmp[key].differentiateCondition =
            this.barcodeData1[u].differentiateCondition
          tmp[key].costTwo = this.barcodeData1[u].costTwo
          tmp[key].costOne = this.barcodeData1[u].costOne
          tmp[key].commodityType = this.barcodeData1[u].commodityType
          tmp[key].commodityName = this.barcodeData1[u].commodityName
          tmp[key].colorNo = this.barcodeData1[u].colorNo
          tmp[key].colorName = this.barcodeData1[u].colorName
          tmp[key].brandedName = this.barcodeData1[u].brandedName
          tmp[key].brandedCompany = this.barcodeData1[u].brandedCompany
          tmp[key].accessoryName = this.barcodeData1[u].accessoryName
        } else {
          tmp[key] = {}
          tmp[key].kindsNumber = this.barcodeData1[u].kindsNumber
          tmp[key].sum = Number(this.barcodeData1[u].sum)
          tmp[key].waveBand = this.barcodeData1[u].waveBand
          tmp[key].vipPrice = this.barcodeData1[u].vipPrice
          tmp[key].supplier = this.barcodeData1[u].supplier
          tmp[key].styleNumber = this.barcodeData1[u].styleNumber
          tmp[key].status = this.barcodeData1[u].status
          tmp[key].statistics = this.barcodeData1[u].statistics
          tmp[key].splitNumber = this.barcodeData1[u].splitNumber
          tmp[key].softwareCustomerId = this.barcodeData1[u].softwareCustomerId
          tmp[key].sizeNo = this.barcodeData1[u].sizeNo
          tmp[key].sizeKind = this.barcodeData1[u].sizeKind
          tmp[key].size = this.barcodeData1[u].size
          tmp[key].sellingPriceTwo = this.barcodeData1[u].sellingPriceTwo
          tmp[key].sellingPriceThree = this.barcodeData1[u].sellingPriceThree
          tmp[key].sellingPriceOne = this.barcodeData1[u].sellingPriceOne
          tmp[key].sellingPriceFour = this.barcodeData1[u].sellingPriceFour
          tmp[key].sellingPrice = this.barcodeData1[u].sellingPrice
          tmp[key].relevanceSize = this.barcodeData1[u].relevanceSize
          tmp[key].quarter = this.barcodeData1[u].quarter
          tmp[key].originalManufacturerKindsNumber =
            this.barcodeData1[u].originalManufacturerKindsNumber
          tmp[key].originalKindsNumber =
            this.barcodeData1[u].originalKindsNumber
          tmp[key].onePrice = this.barcodeData1[u].onePrice
          tmp[key].newSize = this.barcodeData1[u].newSize
          tmp[key].newKindsNumber = this.barcodeData1[u].newKindsNumber
          tmp[key].mnemonicCode = this.barcodeData1[u].mnemonicCode
          tmp[key].matchStyle = this.barcodeData1[u].matchStyle
          tmp[key].manufacturerType = this.barcodeData1[u].manufacturerType
          tmp[key].manufacturerPrice = this.barcodeData1[u].manufacturerPrice
          tmp[key].kindSort = this.barcodeData1[u].kindSort
          tmp[key].image = this.barcodeData1[u].image
          tmp[key].id = this.barcodeData1[u].id
          tmp[key].generalizePrice = this.barcodeData1[u].generalizePrice
          tmp[key].discount = this.barcodeData1[u].discount
          tmp[key].differentiateCondition =
            this.barcodeData1[u].differentiateCondition
          tmp[key].costTwo = this.barcodeData1[u].costTwo
          tmp[key].costOne = this.barcodeData1[u].costOne
          tmp[key].commodityType = this.barcodeData1[u].commodityType
          tmp[key].commodityName = this.barcodeData1[u].commodityName
          tmp[key].colorNo = this.barcodeData1[u].colorNo
          tmp[key].colorName = this.barcodeData1[u].colorName
          tmp[key].brandedName = this.barcodeData1[u].brandedName
          tmp[key].brandedCompany = this.barcodeData1[u].brandedCompany
          tmp[key].accessoryName = this.barcodeData1[u].accessoryName
        }
      }
      this.barcodeData = []
      for (let k in tmp) {
        this.barcodeData.push(tmp[k])
      }
      this.howMany = this.barcodeData.reduce((prev, next) => {
        return prev + next.sum
      }, 0)
      console.log(this.barcodeData)
    },

    csAssignment(str) {
      // 货号里提取色号，色号获取颜色
      // styleColor款色， 色尺colorSize
      let colorSize = str.slice(this.manufacturerBarCode.styleNumber).split('-')
      let tmpLen = 0
      if (this.manufacturerBarCode.styleColorSize) {
        // 型尺色

        if (this.manufacturerBarCode.styleColor) {
          // 款号与尺码之间有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -        MCC-A0001-7-001   ["", "7", "001"]
            this.knSize = colorSize[1]
            this.colorNo = colorSize[2]
          } else {
            // 色号与尺码之间没有 -        MCC-A0001-7001    ["", "7001"]
            tmpLen = colorSize[1].length
            this.knSize = colorSize[1].slice(
              0,
              tmpLen - this.manufacturerBarCode.colorNumber
            )
            this.colorNo = colorSize[1].slice(
              tmpLen - this.manufacturerBarCode.colorNumber
            )
          }
        } else {
          // 款号与尺码之间没有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -      MCC-A00017-001    ["7", "001"]
            this.knSize = colorSize[0]
            this.colorNo = colorSize[1]
          } else {
            // 色号与尺码之间没有 -     MCC-A00017001    ["7001"]
            tmpLen = colorSize[1].length
            this.knSize = colorSize[0].slice(
              0,
              tmpLen - this.manufacturerBarCode.colorNumber
            )
            this.colorNo = colorSize[0].slice(
              tmpLen - this.manufacturerBarCode.colorNumber
            )
          }
        }
      } else {
        // 型色尺

        if (this.manufacturerBarCode.styleColor) {
          // 款号与颜色之间有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -     MCC-A0001-001-7   ["", "001", "7"]
            this.colorNo = colorSize[1]
            this.knSize = colorSize[2]
          } else {
            // 色号与尺码之间没有 -    MCC-A0001-0017   ["", "0017"]
            tmpLen = colorSize[1].length
            this.colorNo = colorSize[1].slice(
              0,
              this.manufacturerBarCode.colorNumber
            )
            this.knSize = colorSize[1].slice(
              this.manufacturerBarCode.colorNumber
            )
          }
        } else {
          // 款号与颜色之间没有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -      MCC-A0001001-7      ["001", "7"]
            this.colorNo = colorSize[0]
            this.knSize = colorSize[1]
          } else {
            // 色号与尺码之间没有 -      MCC-A00010017     ["0017"]
            tmpLen = colorSize[1].length
            this.colorNo = colorSize[0].slice(
              0,
              this.manufacturerBarCode.colorNumber
            )
            this.knSize = colorSize[0].slice(
              this.manufacturerBarCode.colorNumber
            )
          }
        }
      }

      // 颜色
      getColorSeason({ no: this.colorNo, limit: 99999 }).then((res) => {
        // console.log(res)
        if (res.data.code == 200) {
          this.colorName = res.data.data[0].name
        }
      })

      // 尺码
      getSize({ kind: this.manufacturerBarCode.sizeKindId, limit: 99999 }).then(
        (res) => {
          // console.log(res)
          if (res.data.code == 200) {
            let list = res.data.data
            for (let i of list) {
              if (i.size == this.knSize) {
                this.knSizeList = [i]
                break
              }
            }
          }
        }
      )
    },

    //条码扫描
    scanning(e) {
      if (this.searchValue) {
        if (!this.isBarcode) {
          // 手输款号
          getKindsNumberList({ kindsNumberStr: this.searchValue }).then(
            (res) => {
              this.XHList = res.data.data.data
              console.log(res.data)
              if (res.data.data.data.length) {
                this.header = res.data.data.data[0].styleNumber
                this.$emit('inpNumChange')
                // 品牌公司查条码规律详情
                getBarCode({
                  company: res.data.data.data[0].brandedCompany
                }).then((res) => {
                  console.log(res, 'getBarCode')
                  this.manufacturerBarCode = res.data.data[0]
                })

                // console.log(this.manufacturerBarCode)
                // 输入款号显示中间表和尺码信息   ZZZ-AAS
                res.data.data.data.sort((a, b) => {
                  return a.relevanceSize.localeCompare(b.relevanceSize)
                })
                let tmp = res.data.data.data
                this.tmpBarcodeData = tmp
                // console.log(tmp)

                // 中间表  尺码表头
                this.sizeList = [tmp[0].size]
                let isExistSize = 0
                for (const i of tmp) {
                  for (const j of this.sizeList) {
                    if (j == i.size) {
                      isExistSize = 0
                      break
                    }
                    isExistSize = 1
                  }
                  if (isExistSize) {
                    this.sizeList.push(i.size)
                    console.log(this.sizeList)
                  }
                }

                // 中间表
                let tmpCodeData = [
                  { colorNo: tmp[0].colorNo, colorName: tmp[0].colorName }
                ]
                let isExistColor = 0
                for (const i of tmp) {
                  for (const j of tmpCodeData) {
                    if (j.colorName == i.colorName) {
                      isExistColor = 0
                      break
                    }
                    isExistColor = 1
                  }
                  if (isExistColor) {
                    tmpCodeData.push({
                      colorNo: i.colorNo,
                      colorName: i.colorName
                    })
                  }
                }
                tmpCodeData.forEach((e) => {
                  this.sizeList.forEach((f) => {
                    e[f] = ''
                  })
                })
                this.codeData = tmpCodeData
                let codeTable = document.getElementById('codeTable')
                let inputs = codeTable.getElementsByTagName('input')
                // console.log(inputs)
                let int = setInterval(() => {
                  clearInterval(int)
                  inputs[0].focus()
                  inputs[inputs.length - 1].onkeyup = (e) => {
                    if (window.event.keyCode == 13) {
                      this.continueInput()
                      this.codeData = []
                      inputs[inputs.length - 1].onkeyup = () => {}
                    }
                  }
                }, 100)
              } else {
                this.$message('此货号/款号无数据')
                // this.$refs.barcodeInput.focus()
              }
            }
          )
        } else {
          //开条码扫描
          if (this.checkDate == '' || this.warehouseNo == '') {
            this.$message({
              type: 'error',
              message: '调拨日期，仓库编号不能为空'
            })
            return
          }
          if (this.isBarcode && this.radio == '1') {
            var tf
            if (this.isBarcode == false) {
              tf = true
            }

            if (this.isBarcode && this.radio == '1') {
              //货号码
              tf = true
            } else if (this.isBarcode && this.radio == '2') {
              //ID码
              tf = false
            }

            let obj2 = {
              isKindsNumber: tf,
              searchValue: this.searchValue
            }
            console.log(obj2)

            getScanning(obj2).then((res) => {
              let isTrue
              this.isDis = true
              if (res.data.data == null) {
                this.$message({
                  type: 'error',
                  message: '该货号/ID码没有数据'
                })
                return
              } else if (this.isBarcode && this.radio == '2') {
                // var sss = {showCode:this.searchValue}
                this.Rid.push(this.searchValue)
              }
              this.AAa = res.data.data
              for (let e in this.AAa) {
                delete this.AAa[e].id //删除id对象

                this.AAa[e]['sum'] = Number(this.scanNum)
                this.AAa[e]['onePrice'] =
                  this.AAa[e].sellingPrice * (this.AAa[e].discount / 10)
                this.AAa[e]['checkDate'] = this.checkDate
                this.AAa[e]['sequence'] = this.sequence
                this.AAa[e]['warehouseNo'] = this.warehouseNo
                this.AAa[e]['dataSource'] = tf == true ? 1 : 0
                if (tf == false) {
                  this.AAa[e]['rfID'] = this.searchValue
                } else {
                  this.AAa[e]['kNumber'] = this.searchValue
                }
              }

              if (this.barcodeData == '') {
                this.barcodeData = this.AAa
              } else {
                this.merge(this.barcodeData, this.AAa)
                // this.AAa为一条数据 两组数据比较 this.barcodeData数组对象里的kindsNumber与this.AAa数组对象里的kindsNumber一样 sum 就相加 else 就push进this.barcodeData
              }
              console.log(this.barcodeData)

              this.howMany = this.barcodeData.reduce((prev, next) => {
                return prev + next.sum
              }, 0)
              this.searchValue = ''
              // let inpt = document.getElementById('input')
              // inpt.focus()
            })
          } else if (this.isBarcode && this.radio == '2') {
            //扫RFID码
            let existence = this.Rid.indexOf(this.searchValue) //如果有就返回下标 没有返回-1
            if (existence != -1) {
              this.$message.warning({ message: '该ID码已扫描', offset: 400 })
              return
            }

            let obj1 = {
              rfidValue: this.searchValue
            }
            factoryInputScanner(obj1).then((res) => {
              console.log(res)
              if (res.data.data == null) {
                this.$message.error('无此RFID数据')
                return
              } else if (res.data.code == 200 && res.data.data != null) {
                this.Rid.push(this.searchValue)
                this.AAa = [res.data.data]
                for (let e in this.AAa) {
                  delete this.AAa[e].id //删除id对象
                  this.AAa[e]['sum'] = Number(this.scanNum)
                  this.AAa[e]['onePrice'] =
                    this.AAa[e].sellingPrice * (this.AAa[e].discount / 10)
                  this.AAa[e]['checkDate'] = this.checkDate
                  this.AAa[e]['sequence'] = this.sequence
                  this.AAa[e]['warehouseNo'] = this.warehouseNo
                  this.AAa[e]['dataSource'] = tf == true ? 1 : 0
                  this.AAa[e]['rfID'] = this.searchValue
                }

                if (this.barcodeData == '') {
                  this.barcodeData = this.AAa
                } else {
                  this.merge(this.barcodeData, this.AAa)
                  // this.AAa为一条数据 两组数据比较 this.barcodeData数组对象里的kindsNumber与this.AAa数组对象里的kindsNumber一样 sum 就相加 else 就push进this.barcodeData
                }

                this.howMany = this.barcodeData.reduce((prev, next) => {
                  return prev + next.sum
                }, 0)
                this.searchValue = ''
                document.getElementById('input').focus()
                console.log(this.barcodeData)
              }
            })
          }
        }
      }
    },

    merge(target, source) {
      const targetIds = target.reduce(
        (res, v) => res.add(v.kindsNumber),
        new Set()
      )
      const sourceIds = source.reduce(
        (res, v) => res.add(v.kindsNumber),
        new Set()
      )
      target.forEach((v) => sourceIds.has(v.kindsNumber) && v.sum++)
      return target.push(...source.filter((v) => !targetIds.has(v.kindsNumber)))
    },

    rowClick(e) {
      this.deta = e
      this.id = e.id
      console.log(this.deta)
      // console.log(e.id)
    },

    //F8改数量
    preservation() {
      this.showPopup = 'none'
      this.$message({
        type: 'success',
        message: '数量设置成功'
      })
      console.log(this.barcodeData)
    },

    InpFocus() {
      var pFocus = document.getElementById('input')
      // pFocus.focus();
      // pFocus.select();
    }
  },
  mounted() {
    let _this = this
    document.onkeydown = function (event) {
      let e = event || window.event || arguments.callee.caller.arguments[0]
      if (e && e.keyCode == 118) {
        // 按 F7
        // console.log("ffffffffff")
        if (_this.showPopup == 'none') {
          _this.showPopup = 'block'
        } else {
          _this.showPopup = 'none'
        }
      }
    }
  },

  watch: {
    sequenceData(a, b) {
      console.log(a)
      this.sequence = a
    },
    warehouse(a, b) {
      console.log(a)
      this.warehouseNo = a
    },
    searchValue(a, b) {
      if (a) {
        this.searchValue = a.toUpperCase().trim()
      }
    },
    receiptsNumber(a, b) {
      if (a) {
        this.receiptsNumber = a.toUpperCase().trim()
      }
    }
  }
}
</script>

<style scoped>
.middle {
  padding: 10px 15px;
}
.middle p {
  padding-bottom: 10px;
}
._top {
  display: flex;
  width: 100%;
  height: 40px;
  padding: 10px 15px;
  justify-content: space-between;
  background: #f8f8f8;
  font-weight: 700;
}

/* 新建资料 */
.mask {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  opacity: 0.3;
  z-index: 9;
}
.new_build {
  position: fixed;
  /* position: relative; */
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  width: 1100px;
  height: 89%;
  z-index: 99;
  background-color: white;
  overflow: auto;
}
.new_build .build-top {
  height: 40px;
  background-color: #f8f8f8;
  display: flex;
  justify-content: space-between;
  padding: 10px 15px;
}
.build-top p {
  font-weight: 700;
}

.new_build input {
  height: 30px;
  border: buildlid 1px #dcdfe6;
  border-radius: 5px;
  margin-left: 10px;
}
.new_build input:focus {
  outline: none;
  border: buildlid 1px #409eff;
}

.build-info {
  padding: 0 15px;
  padding-bottom: 10px;
  /* border-bottom: buildlid #f2f2f2 2px; */
}
.build-info-1 {
  margin-bottom: 15px;
}
.build-info-1 p {
  display: inline-block;
  width: 80px;
  text-align: right;
  margin-right: 15px;
}

.barcode {
  display: flex;
}

.build-info .barcode p {
  display: inline;
  margin-right: 15px;
}
.build-info .barcode div {
  margin-top: 15px;
}

.barcode-info-1 p,
.barcode-info-2 p {
  display: inline-block;
  width: 96px;
  text-align: right;
  margin-right: 9px;
}

.colorBox,
.infoBox {
  display: inline;
}

.enterBarcode {
  display: flex;
  height: 60px;
  background-color: #f2f2f2;
  margin: 15px 0;
}

.build-btn {
  text-align: right;
}
.po {
  left: 0;
  right: 0;
  position: absolute;
  opacity: 0;
  z-index: 0;
}
.popup {
  width: 400px;
  height: 200px;
  border: 1px solid #dbdbdb;
  box-shadow: 0 2px 2px 2px #dbdbdb;
  z-index: 999;
  position: absolute;
  left: 30%;
  top: 20%;
  /* margin:-100px 0 0 -200px; */
  background: white;
  /* display: block; */
}
.popup_t {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 40px;
  background: rgb(244, 244, 244);
  padding: 8px 15px;
}
.popup_t p {
  font-weight: 700;
}
.popup_c {
  padding: 8px 15px;
}
.popup_button {
  margin: 5px 0 0 0;
  width: 94%;
  height: 30px;
  padding: 0 10px;
  border: 1px solid #dbdbdb;
  border-radius: 3px;
}
.popup_button:focus {
  outline: none;
  border: 1px solid #017fff;
}
.popup_b {
  margin: 10px 0 0 0;
  padding-left: 230px;
}
.build-inp {
  width: 160px;
}
</style>

<style>
.New_build .build-info-4 .el-table .cell {
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 41px;
  padding-right: 10px;
  height: 40px;
}
.New_build .build-info-4 .el-input__inner {
  border: 0px;
}
.New_build .build-info-4 .el-input__inner:focus {
  border: 1px solid #017aff;
}

/* .New_build .build-info-1 .el-input, .New_build .build-info-3 .el-input{
    width: 425px;
  } */
.New_build .build-info-1 .el-input,
.New_build .build-info-2 .el-input {
  margin-top: 10px;
  width: 160px;
}
.New_build .el-input__inner {
  height: 30px !important;
}
.New_build .el-input__icon {
  line-height: 30px !important;
}
.build-info .barcode .el-switch {
  margin: 0 !important;
}

.New_build .enterBarcode .el-input {
  width: 535px;
  margin: 14px 17px;
}
.New_build .barcode .el-radio {
  margin: 5px 5px 0 20px;
}
</style>
